package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.*;
import com.ruoyi.logistic.domain.vo.NetworkOutboundGoAnalyzeVo;
import com.ruoyi.logistic.domain.vo.NetworkOutboundGoVo;
import com.ruoyi.logistic.service.NetworkOutboundGoDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/outboundGo")
@RestController
@Api(tags = "网点财务_出港流向结构分析")
public class NetworkOutboundGoController {
    @Autowired
    private NetworkOutboundGoDetailService networkOutboundGoDetailService;

    @ApiOperation("显示出港流向明细列表")
    @GetMapping("/selectDetailAll")
    public R selectAll(PageDate pageDate){
        List<NetworkOutboundGoDetail> outboundGoDetailList = networkOutboundGoDetailService.selectAll(pageDate);
        if (outboundGoDetailList == null || outboundGoDetailList.size() == 0){
            return R.ok("暂无数据");
        }else {
            return R.ok(PageInfo.info(outboundGoDetailList));
        }
    }
    @ApiOperation("添加出港流向明细")
    @PostMapping("/insertDetail")
    public R insert(@RequestBody NetworkOutboundGoDetail networkOutboundGoDetail){
        Boolean isAdd = networkOutboundGoDetailService.insert(networkOutboundGoDetail);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改出港流向明细")
    @PostMapping("/updateDetail")
    public R update(@RequestBody NetworkOutboundGoDetail networkOutboundGoDetail){
        Boolean isUpdate = networkOutboundGoDetailService.update(networkOutboundGoDetail);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除出港流向明细")
    @PostMapping("/deleteDetailById")
    public R deleteById(Integer id){
        Boolean isDelete = networkOutboundGoDetailService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("搜索出港流向明细")
    @PostMapping("/searchDetail")
    public R searchDetail(@RequestBody NetworkOutboundGoVo vo){
        if (vo.getStartTime() == null || vo.getEndTime() == null){
            return R.ok("请输出查询所需的时间参数");
        }
        if (vo.getNetworkNameId() == null){
            return R.ok("请选择网点信息参数");
        }
        List<NetworkOutboundGoDetail> outboundGoDetailList = networkOutboundGoDetailService.search(vo);
        if (outboundGoDetailList == null || outboundGoDetailList.size() == 0){
            return R.ok("暂无数据");
        }else {
            return R.ok(PageInfo.info(outboundGoDetailList));
        }
    }

    @ApiOperation("汇总出港流向明细")
    @PostMapping("/collect")
    public R collect(@RequestBody NetworkOutboundGoVo vo){
        if (vo.getStartTime() == null || vo.getEndTime() == null){
            return R.ok("请输出查询所需的时间参数");
        }
        if (vo.getNetworkNameId() == null){
            return R.ok("请选择网点信息参数");
        }
        List<NetworkOutboundGoCollect> collectList = networkOutboundGoDetailService.outboundGoCollect(vo);
        if (collectList == null || collectList.size() == 0){
            return R.ok("暂无数据");
        }else {
            return R.ok(PageInfo.info(collectList));
        }
    }

    @ApiOperation("出港流向分析图表")
    @PostMapping("/collectAnalyze")
    public R collectAnalyze(@RequestBody NetworkOutboundGoAnalyzeVo vo){
        if (vo.getStartTime() == null || vo.getEndTime() == null){
            return R.ok("请输出查询所需的时间参数");
        }
        if (vo.getNetworkNameId() == null){
            return R.ok("请选择网点信息参数");
        }
        if (vo.getWeightSection() == null){
            return R.ok("请选择重量参数");
        }
        NetworkOutboundGoAnalyzeAll analyzeList = networkOutboundGoDetailService.collectAnalyze(vo);
        if (analyzeList == null){
            return R.ok("暂无数据");
        }else {
            return R.ok(analyzeList);
        }
    }
}
